const nodemailer = require('nodemailer');

const Email = {
    config: {
        host: 'smtp.qq.com',
        port: 587,
        secure: false, // true for 465, false for other ports
        auth: {
            user: '499353159@qq.com', // generated ethereal user
            pass: 'uiqlyxicnpbfbjfi' // generated ethereal password
        }
    },
    get transporter() {
        return nodemailer.createTransport(this.config)
    },
    get verify() {
        return Math.random().toString().substring(2, 6)
    },
    get time() {
        return Date.now()
    }
}




const send = async (account) => {
  const verify = Email.verify
  const infos = {
    from: '499353159@qq.com', // sender address
    to: account,
    subject: '博客网邮箱验证码， ✔', // Subject line
    text: '注册账号邮箱确认验证码:' + verify // plain text body  注意不能在这里再次调用Email.verify，否则又会随机生成一串字符
  }
  const flog =  await Email.transporter.sendMail(infos)
  return {flog, verify}
}



module.exports = send